package com.hualan.zhsq.service.impl.property;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.property.Activity;
import com.hualan.zhsq.mapper.property.ActivityMapper;
import com.hualan.zhsq.service.property.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ActivityServiceImpl
 * @Description 活动serviceImpl
 * @Author ZheRan
 * @Date 2025年08月04日 下午8:51
 * @Version 1.0
 */
@Service("activityService")
public class ActivityServiceImpl  implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public int add(Activity entity) {
        return activityMapper.insert(entity);
    }

    @Override
    public int edit(Activity entity) {
        return activityMapper.updateById(entity);
    }

    @Override
    public int remove(Integer id) {
        return activityMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return activityMapper.deleteBatchIds(List.of(ids));
    }

    @Override
    public List<Activity> find() {
        return activityMapper.selectList(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Activity entity) {
        Page<Activity> page = new Page<>(pageNum, pageSize);
        Page<Activity> activityPage = activityMapper.selectPage(page, null);
        Map<String, Object> map = new HashMap<>();
        map.put("list",activityPage.getRecords());
        map.put("total", activityPage.getTotal());
        map.put("size", activityPage.getSize());
        return map;
    }

    @Override
    public Activity findById(Integer id) {
        return activityMapper.selectById(id);
    }
}
